import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";

import { HttpRouter } from '../service/httpRouter'
import { HttpService } from '../service/httpService'

@Component({
  selector: 'app-cardlist',
  templateUrl: './cardlist.component.html',
  styleUrls: ['./cardlist.component.less']
})
export class CardlistComponent implements OnInit {

  private cardlist : any[];
  private title = "我的孩子";
  private defaultHead = '../../assets/dog.png';
  constructor(
    private httpRouter : HttpRouter,
    private httpService : HttpService,
    public router : Router
  ) { }

  ngOnInit() {
    this.getList();

  }
  getList(){
    this.httpService.get(this.httpRouter.getChildListUrl).subscribe(data => {
      if(data.code === "10200"){
        this.cardlist = data.data;
      }
    });
  }

  getCourses(childId){
    for(let i = 0; i < this.cardlist.length; i++){
      if(this.cardlist[i].childId == childId){
        let child = JSON.stringify(this.cardlist[i]);
        sessionStorage.setItem("child",child);
      }
    }
    this.router.navigateByUrl('courseslist/'+childId);
  }


}
